<template>
	<view>
		<view class="" v-if="payment == 'MafubaoWeixin' || payment == 'MafubaoAlipay'">
			<web-view :src="paypage"></web-view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				paypage: '',
				payment:''
			}
		},
		onLoad(params) {
			let self = this;
			let orderId = params.id; //订单id
			let paymentId = params.payment_id; //支付方式id
			this.payment = params.payment; //支付方式唯一标记
			let orderPayUrl = this.requestUrl.orderPay;

			let payParams = {
				data: {
					id: orderId,
					payment_id: paymentId,
					call_back_url:this.requestUrl.host+'/h5/#/pages/pay/returnUrl'
				}
			}
			
			this.util.request(orderPayUrl, 'post', function(res) {
				// #ifdef H5
					// h5端分为 支付宝支付和码付宝-支付宝支付
					// 支付宝
					if(self.payment == 'Alipay' && res.statusCode==200){
						const div = document.createElement('div');
						/* 此处form就是后台返回接收到的数据 */
						div.innerHTML = res.data
						document.body.appendChild(div)
						document.forms[0].submit();
					}
				// #endif
				if (res.data.code == 0) {
					// 货到付款 self.payment == 'DeliveryPayment'
					if(res.data.data.is_online_pay==0){
						uni.redirectTo({
							url: '/pages/pay/returnUrl',
						});
					}
					// 在线支付
					if(res.data.data.is_online_pay==1){
						// #ifdef H5
							// 码付宝-支付宝
							if(self.payment == 'MafubaoAlipay'){
								self.paypage = res.data.data.data;
							}
						// #endif
						
						// #ifdef APP-PLUS
							let appOrderInfo='';
							if(self.payment == 'Alipay'){
								appOrderInfo=res.data.data.data;
								uni.requestPayment({
									provider:'alipay',
									orderInfo:appOrderInfo,
									success:function() {
										console.log('success:' + JSON.stringify(res));
									}
								})
							}
						// #endif
					}	
				}
			}, payParams);
		},
		methods: {

		}
	}
</script>

<style>

</style>
